<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<head>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
</head>
<!-- 全局css引入 必须 -->
<link href="<%=basePath%>/style/style.css" rel="stylesheet" type="text/css">
<link href="<%=basePath%>/style/global.css" rel="stylesheet" type="text/css">
<!--如用到ext必须引入 -->
<jsp:include page="/extInclude.jsp" />
<link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/ux/css/Portal.css" />
<script type="text/javascript" src="<%=path%>/js/ext/ux/TabCloseMenu.js"></script>
<script type="text/javascript" src="<%=path%>/js/ext/ux/Portal.js"></script>
<script type="text/javascript" src="<%=path%>/js/ext/ux/PortalColumn.js"></script>
<script type="text/javascript" src="<%=path%>/js/ext/ux/Portlet.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/ext/ux/Toast.js"></script>
<link href="<%=basePath%>/style/desktop.css" rel="stylesheet" type="text/css">
<link href="<%=basePath%>/style/style.css" rel="stylesheet" type="text/css">
<link href="<%=basePath%>/style/global.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<%=basePath%>/js/ScrollText.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/core/AppUtil.js"></script>
<style>
body,dl,dt,dd,ul,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,img,textarea,blockquote,p
	{
	padding: 0;
	margin: 0;
	background-color: #FAFAFF;
}

.x-panel-header-text {
	padding-left: 5px;
	padding-top: 10px;
	font-size: x-small;
	color: #FA572D;
}

.x-panel-icon {
	padding-bottom: 30px;
}
</style>
<script type="text/javascript">
Ext.onReady(function(){
Ext.ns("App");
var PortalItem = function(a, b, c) {
	this.panelid = a;
	this.colno = b;
	this.rowno = c;
};
var UserInfo = function(d, a, c, f, e, b) {
	this.userId = d;
	this.fullname = a;
	this.depId = c;
	this.depName = f;
	this.rights = e;
	this.portalConfig = b;
};
/**
 * 将布局信息存储于cookies中，使得保存布局后不需要重新登陆即可保持布局，
 * 
 * 如果cookies为空，则从用户sesssion中取的布局信息
 */
if (getCookie("portals")) {
	var curUserInfo = {};
	curUserInfo.portalConfig = getCookie("portals");
} else {
	var curUserInfo = _curUser;
}
function isGranted(a) {
	if (curUserInfo.rights.indexOf("__ALL") != -1) {
		return true;
	}
	if (curUserInfo.rights.indexOf(a) != -1) {
		return true;
	}
	return false;
};
${portalString}
PanelSelectorWin = Ext.extend(Ext.Window, {
	formPanel : null,
	buttons : null,
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUI();
		PanelSelectorWin.superclass.constructor.call(this, {
					id : "PanelSelectorWin",
					title : "选择显示模块",
					layout : "fit",
					height : 220,
					width : 300,
					modal : true,
					defaults : {
						padding : "5"
					},
					buttons : this.buttons,
					buttonAlign : "center",
					items : this.formPanel
				});
	},
	initUI : function() {
		this.formPanel = new Ext.FormPanel({
					id : "PanelSelectorForm",
					layout : "column",
					items : [{
								layout : "form",
								columnWidth : 0.5,
								border : false,
								items : [${selectString1}]
							}, {
								layout : "form",
								columnWidth : 0.5,
								border : false,
								items : [${selectString2}]
							}]
				});
		var portal = Ext.getCmp("Portal");
		curUserInfo.portalConfig = [];
		var items = portal.items;
		for (var i = 0; i < items.length; i++) {
			var v = items.itemAt(i);
			for (var j = 0; j < v.items.getCount(); j++) {
				var m = v.items.itemAt(j);
				var portalItem = new PortalItem(m.id, i, j);
				curUserInfo.portalConfig.push(portalItem);
			}
		}
		var confs = curUserInfo.portalConfig;
		for (var i = 0; i < confs.length; i++) {
			var panelView = confs[i].panelid;
			var panelCheck = Ext.getCmp(panelView + "CheckBox");
			if (panelCheck != null) {
				panelCheck.setValue(true);
				panelCheck.disable();
			}
		}
		this.buttons = [{
			xtype : "button",
			text : "确定",
			iconCls : "btn-save",
			handler : function() {
				var fd = Ext.getCmp("PortalItem");
				var portal = Ext.getCmp("Portal");
				var array = [${arr}];
				for (var v = 0; v < array.length; v++) {
					var check = Ext.getCmp(array[v] + "CheckBox");
					if (check != null) {
						if (check.getValue() && Ext.getCmp(array[v]) == null) {
							var panel = eval("new " + array[v] + "()");
							fd.add(panel);
						}
					}
				}
				fd.doLayout();
				portal.doLayout();
				Ext.getCmp("PanelSelectorWin").close();
			}
		}, {
			xtype : "button",
			text : "取消",
			iconCls : "btn-cancel",
			handler : function() {
				Ext.getCmp("PanelSelectorWin").close();
			}
		}];
	}
});
AppHome = Ext.extend(Ext.Panel, {
	portalPanel : null,
	toolbar : null,
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUIComponents();
		AppHome.superclass.constructor.call(this, {
					//title : "首 页",
					closable : false,
					id : "AppHome",
					iconCls : "menu-company",
					layout : "fit",
					defaults : {
						padding : "0 5 0 0"
					},
					tbar : this.toolbar,
					items : this.portalPanel
				});
	},
	initUIComponents : function() {
		this.toolbar = new Ext.Toolbar({
			height : 30,
			items : ["->",{
						xtype : "button",
						text : "添加模块",
						iconCls : "btn-add",
						handler : function() {
							new PanelSelectorWin().show();
						}
					}, {
						xtype : "button",
						text : "保存布局",
						iconCls : "btn-save",
						handler : function() {
							var portal = Ext.getCmp("Portal");
							curUserInfo.portalConfig = [];
							var items = portal.items;
							for (var i = 0; i < items.length; i++) {
								var v = items.itemAt(i);
								for (var j = 0; j < v.items.getCount(); j++) {
									var m = v.items.itemAt(j);
									var portalItem = new PortalItem(m.id, i, j);
									curUserInfo.portalConfig.push(portalItem);
								}
							}
							Ext.Ajax.request({
								method : "post",
								url : _ctxPath + "/savePortal.do?op=ajax",
								success : function(request) {
									setCookie(
											"portals",
											Ext
													.encode(curUserInfo.portalConfig));
									Ext.ux.Toast.msg("操作信息", "保存成功");
								},
								failure : function(request) {
									Ext.MessageBox.show({
												title : "操作信息",
												msg : "信息保存出错，请联系管理员！",
												buttons : Ext.MessageBox.OK,
												icon : "ext-mb-error"
											});
								},
								params : {
									items : Ext
											.encode(curUserInfo.portalConfig)
								}
							});
						}
					}]
		});
		var tools = [{
					id : "gear",
					handler : function() {
						Ext.Msg.alert("Message",
								"The Settings tool was clicked.");
					}
				}, {
					id : "close",
					handler : function(e, target, panel) {
						panel.ownerCt.remove(panel, true);
					}
				}];
		var confs = Ext.decode(curUserInfo.portalConfig);
		if (confs == null || confs == undefined || confs.length < 1) {
			confs = new Array();
			/**var p1 = {
				panelid : "Portal1View",
				colno : 1,
				rowno : 2
			};
			var p2 = {
				panelid : "Portal6View",
				colno : 0,
				rowno : 0
			};
			var p3 = {
				panelid : "Portal100000000005View",
				colno : 0,
				rowno : 1
			};
			var p4 = {
				panelid : "Portal3View",
				colno : 0,
				rowno : 2
			};
			var p5 = {
				panelid : "Portal100000000008View",
				colno : 1,
				rowno : 0
			};
			var p6 = {
				panelid : "Portal100000000009View",
				colno : 1,
				rowno : 1
			};
			var p7 = {
				panelid : "Portal4View",
				colno : 1,
				rowno : 3
			};**/
			var p8 = {
				panelid : "Portal4View",
				colno : 0,
				rowno : 0
			};
			/**confs.push(p1);
			confs.push(p2);
			confs.push(p3);
			confs.push(p4);
			confs.push(p5);
			confs.push(p6);
			confs.push(p7);**/
			confs.push(p8);
		}
		var column0 = [];
		var column1 = [];
		for (var v = 0; v < confs.length; v++) {
			var o = confs[v];
			// alert("new " + confs[v].panelid + "()")
			//try {
			//if (confs[v].colno == 0) {
				column0.push(eval("new " + confs[v].panelid + "()"));
			//} else {
			//	column1.push(eval("new " + confs[v].panelid + "()"));
			//}
			//}catch(e){
			///	Ext.ux.Toast.msg(e);
			//}
		}
		this.portalPanel = {
			id : "Portal",
			xtype : "portal",
			region : "center",
			margins : "35 5 5 0",
			items : [{
						columnWidth : 0.99,
						style : "padding:10px 0 10px 10px",
						id : "PortalItem",
						items : column0
					}, {
						columnWidth : 0.01,
						hide:true,
						style : "padding:10px 10px 10px 10px",
						items : column1
					}]
		};
	}
});
App.init = function() {
	var app = new AppHome({
				height : window.screen.height-300
			});
	app.render("main");
}
App.init()
});
</script>
<body scroll="no">
	<div id="main"></div>
	<div id="hello-win" class="x-hidden">
		<div class="x-window-header">
			你好！${userinfor.ygxm}
		</div>
</body>